home *** CD-ROM | disk | FTP | other *** search
/ Video Toaster 4.3 / Video Toaster v4.3.iso / 3.1 / toasterall / arexx_examples / tpaint / txbrush.rexx < prev    next >
OS/2 REXX Batch file  |  1992-01-29  |  4KB  |  117 lines

  1. /* TxBrush.rexx -- Resize a brush to be a multiple of 64 pixels wide */
  2. /* By Arnie Cachelin © 1992 NewTek Inc.                              */
  3.  
  4. /*
  5.   This program will resize a brush so that the width is a multiple of 64 pixels
  6.   for use as texture map in LightWave3D.  You must tell it the width and
  7.   height of the brush, along with its name.  The height won't be changed.
  8.   To use the program, make sure TPaint is running, rexx is installed and
  9.   this script is in the current directory or in 'REXX:'.  From a shell,
  10.   simply type 'rx TxBrush w h name'.  Where w is the brush width, h is the
  11.   height and name is the file name for the brush.  If a second name is given,
  12.   the  brush  will  be saved with that name otherwise the brush will be saved
  13.   under the same name with '.map' appended. The width of a brush can be
  14.     determined by clicking the right mouse button in paint.
  15.  */
  16.  
  17. ARG w h infile outfile
  18. if w="" | h="" | infile="" then do
  19.   say "Usage: rx TxBrush w h name [save name]"
  20.   say "       w = brush width in pixels"
  21.   say "       h = brush height in pixels"
  22.   say "       name = brush file name"
  23.   exit
  24. end
  25.  
  26. PageWide=752
  27. PageHigh=480
  28. maxsize=704
  29. portname="DigiPaint"
  30.  
  31. Address "DigiPaint"     /* Tell ARexx where commands go  */
  32.  
  33. if pos(portname,show(ports))=0 then do
  34.   say "Can't find ToasterPaint!"
  35.   exit
  36.   end
  37.  
  38. if infile~="" then do
  39.   if ~exists(infile) then do
  40.     say "Can't find input image file "infile
  41.     exit
  42.   end
  43.   Call LoadBrush(infile) /* if no name is given, use current screen! */
  44.   if outfile="" then outfile=infile".map"
  45. end
  46.  
  47. if w>pagewide then size=maxsize
  48. else size=(w%64+1)*64
  49. 'Bcop'          /* Copy brush to Swap brush */
  50. 'Cbx0'                    /* Set color to black */
  51. 'Clrs'          /* Clear screen  */
  52. call MapBrush(0,0,size-1,h-1)
  53. call CutBrush(0,0,size-1,h-1)
  54. Call SaveBrush(outfile)
  55. exit
  56.  
  57. MapBrush: PROCEDURE  /* Size swap brush into rectangle with corners at (x1,y1) and (x2,y2) */
  58.   arg x1, y1, x2, y2 /* if there is no swap brush, whole screen is used! */
  59.   'Pmcl'        /* Normal draw Mode */
  60.     'Hvof'                /* Blend gradient off (edge=center) */
  61.     'Maxc'                /* Set (center) transparency off */
  62.   'Flon'        /* Fill On */
  63.   'Aaon'        /* Anti-alias on */
  64.   'Txma'        /* Texture mapping on, fill on, draw rectangles  */
  65.   'Drre'        /* Draw Rectangles */
  66.   'Pend' x1 y1  /* Get in top Left corner  */
  67.   'Penu' x2 y2  /* lift pen  */
  68.   'Flof'        /* fill off  */
  69.   'Pmcl'        /* Normal draw Mode */
  70.   return
  71.  
  72. CutBrush: PROCEDURE  /* Cut out a brush with corners at (x1,y1) and (x2,y2) */
  73.   arg x1, y1, x2, y2
  74.   'Dotb'        /* smallest brush size */
  75.   'Drre'        /* Rectangle mode  */
  76.   'Scis'        /* Scissors on, for cutting a brush  */
  77.   'Pend' x1 y1  /* Get in top Left corner  */
  78.   'Penu' x2 y2  /* lift pen to get brush!  */
  79.   return 0
  80.  
  81. LoadBrush: PROCEDURE   /* Load Brush */
  82.   arg filename
  83.   'Lobr'                 /* Call file requester  */
  84.     Call SetFile(filename)
  85.   return
  86.  
  87. SaveBrush: PROCEDURE   /* Save Brush */
  88.   arg filename
  89.   'Sabr'                 /* Call file requester  */
  90.     Call SetFile(filename)
  91.   return
  92.  
  93.  
  94. SetFile: PROCEDURE           /* Select file in current requester */
  95.   arg file
  96.   dirname=GetPathName(file)
  97.   'Dnam'dirname          /* Enter file path  */
  98.   'Dsel'                 /* Hit return on directory */
  99.   filename=GetFileName(file)
  100.   'Fnam'filename         /* Enter File name  */
  101.   'Okls'                 /* Hit the OK button  */
  102.   return
  103.  
  104. GetFileName: procedure  /* Extract file name from full file specification */
  105.    ARG fullfile
  106.    c = lastpos("/",fullfile)
  107.    if c = 0 then c = lastpos(":",fullfile)
  108.    return substr(fullfile, c + 1)
  109.  
  110. GetPathName: procedure  /* Extract directory name from full file specification */
  111.    ARG fullfile
  112.    c = lastpos("/",fullfile)
  113.    if c = 0 then c = lastpos(":",fullfile)
  114.    return left(fullfile,c)
  115.  
  116.  
  117.